#include <iostream>
#include <vector>
#include "segment.h"
#include "Random_Input.h"
#include "Left_turn.h"

bool bounding_box_check(const Segment& s1, const Segment& s2)
{
   return !(((s1.a.x < s2.a.x) && (s1.a.x < s2.b.x) && (s1.b.x < s2.a.x) && (s1.b.x < s2.b.x)) ||
          ((s2.a.x < s1.a.x) && (s2.a.x < s1.b.x) && (s2.b.x < s1.a.x) && (s2.b.x < s1.b.x)) ||
          ((s1.a.y < s2.a.y) && (s1.a.y < s2.b.y) && (s1.b.y < s2.a.y) && (s1.b.y < s2.b.y)) ||
          ((s2.a.y < s1.a.y) && (s2.a.y < s1.b.y) && (s2.b.y < s1.a.y) && (s2.b.y < s1.b.y)));

}

bool is_intersected(const Segment& s1, const Segment& s2)
{
   if (!bounding_box_check(s1, s2))
    {
        return false;
    }
    return (left_turn(s1.a, s1.b, s2.a) * left_turn(s1.a, s1.b, s2.b) <= 0
         && left_turn(s2.a, s2.b, s1.a) * left_turn(s2.a, s2.b, s1.b) <= 0);

}

int main()
{
   Segment a, b;
   int amount;
   int type;
   std::vector<bool> ans;

   std::cin >> amount >> type;
   
   if (type == 0) 
   {
      for (int i = 0; i < amount; i++) 
      {
         double x1, y1, x2, y2;

         std::cin >> x1 >> y1 >> x2 >> y2;
         a = Segment(Point(x1, y1), Point(x2, y2));

         std::cin >> x1 >> y1 >> x2 >> y2;
         b = Segment(Point(x1, y1), Point(x2, y2));

         ans.push_back(is_intersected(a, b));
      }
   }

   if (type == 1)
   {
      int seed;
      std::cin >> seed;
      RandomInput in(seed);

      for (int i = 0; i < amount; i++)
      {
         a = Segment(Point(in.get_double(), in.get_double()), Point(in.get_double(), in.get_double()));
         b = Segment(Point(in.get_double(), in.get_double()), Point(in.get_double(), in.get_double()));
         ans.push_back(is_intersected(a, b));
      }
   }

   int p = 1;
   int res = 0;
   for (size_t i = 0; i < ans.size(); ++i, p *= 239) {
      if (ans[i])
         res += p;
   }
  
   std::cout<<res<<"\n";

   return 0;
}
